package com.ruoyi.web.controller.recommend.admin;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.OperatorType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.student.domain.StudentBaseInfo;
import com.ruoyi.student.domain.StudentRecommendInfo;
import com.ruoyi.student.domain.vo.*;
import com.ruoyi.student.service.IStudentBaseInfoService;
import com.ruoyi.student.service.IStudentRecommendInfoService;
import com.ruoyi.student.service.IStudentService;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 管理员推荐表管理
 */
@RestController("AdminStudentRecommendManageController")
@RequestMapping("/admin/student/recommend")
public class AdminStudentRecommendManageController extends BaseController {
    @Resource
    private IStudentBaseInfoService studentBaseInfoService;


    @Resource
    private IStudentRecommendInfoService studentRecommendInfoService;

    /**
     * 学生操作（多表操作）
     */
    @Resource
    private IStudentService studentService;


    @Resource
    private ISysUserService userService;

    /**
     * 查询学生推荐表信息列表
     *
     * @param vo
     * @return
     */
    @PreAuthorize("@ss.hasPermi('admin:student:recommend:list')")
    @Log(title = "管理员-查询学生推荐表信息列表", operatorType = OperatorType.MANAGE, businessType = BusinessType.QUERY)
    @GetMapping("/infos")
    public AjaxResult infos(StudentRecommendInfoListSearchVo vo) {
        return success(studentService.selectStudentRecommendInfoList(vo));
    }


    /**
     * 获取学生推荐表信息列表(分页)
     *
     * @param vo
     * @return
     */
    @PreAuthorize("@ss.hasPermi('admin:student:recommend:list')")
    @Log(title = "管理员-查询学生推荐表信息列表（分页）", operatorType = OperatorType.MANAGE, businessType = BusinessType.QUERY)
    @GetMapping("/list")
    public TableDataInfo list(StudentRecommendListSearchVo vo) {
        startPage();
        List<StudentRecommendListVo> list = studentService.selectStudentRecommendList(vo);
        return getDataTable(list);
    }


    /**
     * 获取学生推荐表信息
     *
     * @param code
     * @return
     */
    @PreAuthorize("@ss.hasPermi('admin:student:recommend:info')")
    @Log(title = "管理员-查询单个学生推荐表信息", operatorType = OperatorType.MANAGE, businessType = BusinessType.QUERY)
    @GetMapping("/info/{code}")
    public AjaxResult info(@PathVariable("code") String code) {
        if (StringUtils.isEmpty(code)) {
            return error("无效学号参数");
        }
        StudentBaseInfo studentBaseInfo = studentBaseInfoService.selectStudentBaseInfoByCode(code);
        if (studentBaseInfo == null) {
            return error("学号参数不正确");
        }
        StudentRecommendInfo studentRecommendInfo = studentRecommendInfoService.selectStudentRecommendInfoByCode(code);
        SelectStudentRecommendInfoVo selectStudentRecommendInfoVo = new SelectStudentRecommendInfoVo();

        selectStudentRecommendInfoVo.setName(studentBaseInfo.getName());
        selectStudentRecommendInfoVo.setCode(studentBaseInfo.getCode());

        selectStudentRecommendInfoVo.setSex(studentBaseInfo.getSex());//性别

        selectStudentRecommendInfoVo.setPoliticalStatus(studentBaseInfo.getPoliticalStatus());
        selectStudentRecommendInfoVo.setForeignLanguageEvel(studentRecommendInfo.getForeignLanguageEvel());
        selectStudentRecommendInfoVo.setComputerLevel(studentRecommendInfo.getComputerLevel());
        selectStudentRecommendInfoVo.setJobIntention(studentRecommendInfo.getJobIntention());

        selectStudentRecommendInfoVo.setPhoneNumber(studentBaseInfo.getPhoneNumber());
        selectStudentRecommendInfoVo.setQq(studentRecommendInfo.getQq());
        selectStudentRecommendInfoVo.setEmail(studentRecommendInfo.getEmail());

        selectStudentRecommendInfoVo.setHomeAddress(studentRecommendInfo.getHomeAddress());
        selectStudentRecommendInfoVo.setHomeCode(studentRecommendInfo.getHomeCode());
        selectStudentRecommendInfoVo.setHomePhone(studentRecommendInfo.getHomePhone());

        selectStudentRecommendInfoVo.setIsHkInSchool(studentRecommendInfo.getIsHkInSchool());
        selectStudentRecommendInfoVo.setIsCityStudent(studentRecommendInfo.getIsCityStudent());
        selectStudentRecommendInfoVo.setSource(studentBaseInfo.getSource());//生源所在地

        selectStudentRecommendInfoVo.setRxqdaszdw(studentRecommendInfo.getRxqdaszdw());
        selectStudentRecommendInfoVo.setRxqhkszdpcs(studentRecommendInfo.getRxqhkszdpcs());

        selectStudentRecommendInfoVo.setRewardPunishmentPrize1(studentRecommendInfo.getRewardPunishmentPrize1());
        selectStudentRecommendInfoVo.setRewardPunishmentPrize2(studentRecommendInfo.getRewardPunishmentPrize2());
        selectStudentRecommendInfoVo.setRewardPunishmentPrize3(studentRecommendInfo.getRewardPunishmentPrize3());
        selectStudentRecommendInfoVo.setRewardPunishmentPrize4(studentRecommendInfo.getRewardPunishmentPrize4());
        selectStudentRecommendInfoVo.setRewardPunishmentPrize5(studentRecommendInfo.getRewardPunishmentPrize5());

        selectStudentRecommendInfoVo.setWorkContent1(studentRecommendInfo.getWorkContent1());
        selectStudentRecommendInfoVo.setWorkContent2(studentRecommendInfo.getWorkContent2());
        selectStudentRecommendInfoVo.setWorkContent3(studentRecommendInfo.getWorkContent3());
        selectStudentRecommendInfoVo.setWorkContent4(studentRecommendInfo.getWorkContent4());
        selectStudentRecommendInfoVo.setWorkContent5(studentRecommendInfo.getWorkContent5());
        selectStudentRecommendInfoVo.setQualification(studentRecommendInfo.getQualification());

        selectStudentRecommendInfoVo.setDepartmentOpinion(studentRecommendInfo.getDepartmentOpinion());

        selectStudentRecommendInfoVo.setStudentRecommendSubmit(studentRecommendInfo.getStudentRecommendSubmit());
        selectStudentRecommendInfoVo.setCounselorRecommendCheck(studentRecommendInfo.getCounselorRecommendCheck());

        //学籍相关信息
        selectStudentRecommendInfoVo.setCampus(studentBaseInfo.getCampus());
        selectStudentRecommendInfoVo.setGrade(studentBaseInfo.getGrade());
        selectStudentRecommendInfoVo.setDepartment(studentBaseInfo.getDepartment());
        selectStudentRecommendInfoVo.setMajor(studentBaseInfo.getMajor());
        selectStudentRecommendInfoVo.setMajorDirection(studentBaseInfo.getMajorDirection());
        selectStudentRecommendInfoVo.setStudyTime(studentBaseInfo.getStudyTime());
        selectStudentRecommendInfoVo.setClassNum(studentBaseInfo.getClassNum());
        selectStudentRecommendInfoVo.setGraduationYear(studentBaseInfo.getGraduationYear());
        selectStudentRecommendInfoVo.setEnterTime(studentBaseInfo.getEnterTime());
        selectStudentRecommendInfoVo.setGraduateTime(studentBaseInfo.getGraduateTime());
        //获取当前学生的辅导员
        SysUser sysUser = userService.selectUserByUserName(studentBaseInfo.getCounsellorCode());
        if (sysUser != null) {
            selectStudentRecommendInfoVo.setCounsellorName(sysUser.getNickName());
            selectStudentRecommendInfoVo.setCounsellorCode(sysUser.getUserName());
            selectStudentRecommendInfoVo.setCounsellorPhone(sysUser.getPhonenumber());
        } else {
            selectStudentRecommendInfoVo.setCounsellorName("该生暂未绑定辅导员");
            selectStudentRecommendInfoVo.setCounsellorCode("该生暂未绑定辅导员");
            selectStudentRecommendInfoVo.setCounsellorPhone("该生暂未绑定辅导员");
        }
        return success(selectStudentRecommendInfoVo);
    }


    /**
     * 打印推荐表
     *
     * @return
     */
//    @GetMapping("/print")
//    public AjaxResult print() {
//        return success();
//    }


    /**
     * 审核推荐表
     *
     * @return
     */
//    @GetMapping("/check")
//    public AjaxResult check() {
//        return success();
//    }


    /**
     * 查询核对单列表
     *
     * @param vo
     * @return
     */
    @PreAuthorize("@ss.hasPermi('admin:student:recommend:checkList')")
    @Log(title = "管理员-查询学生推荐表信息核对单列表", operatorType = OperatorType.MANAGE, businessType = BusinessType.QUERY)
    @GetMapping("/checkTable")
    public AjaxResult selectCheckTableList(SelectCheckTableSearchVo vo) {
        return success(studentService.selectCheckTableList(vo));
    }


    /**
     * 导出学生推荐表填写情况
     *
     * @param response
     * @param vo
     */
    @PreAuthorize("@ss.hasPermi('admin:student:recommend:export')")
    @Log(title = "管理员-导出学生推荐表填写情况", operatorType = OperatorType.MANAGE, businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StudentListSearchVo vo) {
        List<StudentRecommendFillStateListVo> list = studentService.selectStudentRecommendFillStateList(vo);
        ExcelUtil<StudentRecommendFillStateListVo> util = new ExcelUtil<>(StudentRecommendFillStateListVo.class);
        util.exportExcel(response, list, "学生基础信息数据");
    }


}
